I’m stuck on Stage #YZ1
I’ve tried …
Here are my logs:
response "$-1\r\n"
[tester::#LA7] Received bytes: "$-1\r\n"
[tester::#LA7] Received RESP null bulk string: "$-1\r\n"
[tester::#LA7] Expected simple string or bulk string, got NIL
[tester::#LA7] Test failed
[tester::#LA7] Terminating program
[tester::#LA7] Program terminated successfully
And here’s a snippet of my code:
const delimiter = '\r\n'
export class RespSerializer {
public static serialize(data: IRespData | null) {
if (!data) {
return RespSerializer.serializeBulkString(null)
}
console.log("data", data)
switch (data.type) {
case RespDataType.ArrayType:
return RespSerializer.serializeArrays(data.value as IRespData[])
case RespDataType.BulkString:
return RespSerializer.serializeBulkString(data.value as string)
case RespDataType.SimpleString:
return RespSerializer.serializeSimpleString(data.value as string)
case RespDataType.Integer:
return RespSerializer.serializeInteger(data.value as number)
case RespDataType.Error:
return RespSerializer.serializeError(data.value as string)
default:
//handle default
}
}
public static serializeSimpleString(str: string) {
return `${RespDataType.SimpleString}${str}${delimiter}`
}
public static serializeInteger(num: number) {
return `${RespDataType.Integer}${num}${delimiter}`
}
public static serializeError(str: string) {
return `${RespDataType.Error}${str}${delimiter}`
}
public static serializeBulkString(str: string | null) {
if (str === null) {
return `${RespDataType.BulkString}${-1}${delimiter}`
}
return `${RespDataType.BulkString}${str.length}${delimiter}${str}${delimiter}`
}
public static serializeArrays(data: IRespData[]) {
let res = ""
data.map((item) => {
const itemStr = this.serialize(item)
res += itemStr
})
return `${RespDataType.ArrayType}${data.length}${delimiter}${res}`
}
}
public static serializeBulkString(str: string | null) {
if (str === null) {
return `${RespDataType.BulkString}${-1}${delimiter}`
}
return `${RespDataType.BulkString}${str.length}${delimiter}${str}${delimiter}`
}