<commit_before>import { Reader } from '../buffer/reader';
import { Writer } from '../buffer/writer';

import { IpcPacketReader } from './ipcPacketReader';
import { IpcPacketWriter } from './ipcPacketWriter';
import { IpcPacketHeader } from './ipcPacketHeader';
import { JSONLike, JSONParser } from 'json-helpers';

export class IpcPacketCore extends IpcPacketHeader {
    protected _reader: IpcPacketReader;
    protected _writer: IpcPacketWriter;

    constructor(rawHeader?: IpcPacketHeader.RawData, json?: JSONLike) {
        super(rawHeader);
        this._reader = new IpcPacketReader(json);
        this._writer = new IpcPacketWriter(json);
    }

    read(bufferReader: Reader): any | undefined {
        return this._reader.read(bufferReader, (rawHeader) => {
            this._rawHeader = rawHeader;
        });
    }

    write(bufferWriter: Writer, data: any): void {
        this._writer.write(bufferWriter, data, (rawHeader) => {
            this._rawHeader = rawHeader;
        });
    }<commit_msg>add json option<commit_after>import { Reader } from '../buffer/reader';
import { Writer } from '../buffer/writer';

import { IpcPacketReader } from './ipcPacketReader';
import { IpcPacketWriter } from './ipcPacketWriter';
import { IpcPacketHeader } from './ipcPacketHeader';
import { JSONLike } from 'json-helpers';

export class IpcPacketCore extends IpcPacketHeader {
    protected _reader: IpcPacketReader;
    protected _writer: IpcPacketWriter;

    constructor(rawHeader?: IpcPacketHeader.RawData, json?: JSONLike) {
        super(rawHeader);
        this._reader = new IpcPacketReader(json);
        this._writer = new IpcPacketWriter(json);
    }

    read(bufferReader: Reader): any | undefined {
        return this._reader.read(bufferReader, (rawHeader) => {
            this._rawHeader = rawHeader;
        });
    }

    write(bufferWriter: Writer, data: any): void {
        this._writer.write(bufferWriter, data, (rawHeader) => {
            this._rawHeader = rawHeader;
        });
    }
{'fraction_non_alphanumeric': 0.12152777777777778, 'fraction_numerical': 0.0, 'mean_word_length': 3.2552742616033754, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5257944', 'n_tokens_mistral': 574, 'n_tokens_neox': 564, 'n_words': 133}