48 lines
1.1 KiB
TypeScript
48 lines
1.1 KiB
TypeScript
|
import { DeviceType, LocaleCode } from '@ucap-webmessenger/core';
|
||
|
import {
|
||
|
ProtocolRequest,
|
||
|
ProtocolResponse,
|
||
|
ProtocolEncoder,
|
||
|
PacketBody,
|
||
|
PacketBodyValue,
|
||
|
ProtocolDecoder,
|
||
|
ProtocolMessage
|
||
|
} from '@ucap-webmessenger/protocol';
|
||
|
|
||
|
export interface BuddyUpdateRequest extends ProtocolRequest {
|
||
|
// 0. 사용자SEQ(n)
|
||
|
userSeq: number;
|
||
|
// 1. 즐겨찾기여부(y)
|
||
|
favorit: boolean;
|
||
|
}
|
||
|
|
||
|
export interface BuddyUpdateResponse extends ProtocolResponse {
|
||
|
// 0. 사용자SEQ(n)
|
||
|
userSeq: number;
|
||
|
// 1. 즐겨찾기여부(y)
|
||
|
favorit: boolean;
|
||
|
}
|
||
|
|
||
|
export const encodeBuddyUpdate: ProtocolEncoder<BuddyUpdateRequest> = (
|
||
|
req: BuddyUpdateRequest
|
||
|
) => {
|
||
|
const bodyList: PacketBody[] = [];
|
||
|
|
||
|
bodyList.push({ type: PacketBodyValue.Integer, value: req.userSeq });
|
||
|
bodyList.push({
|
||
|
type: PacketBodyValue.String,
|
||
|
value: req.favorit ? 'Y' : 'N'
|
||
|
});
|
||
|
|
||
|
return bodyList;
|
||
|
};
|
||
|
|
||
|
export const decodeBuddyUpdate: ProtocolDecoder<BuddyUpdateResponse> = (
|
||
|
message: ProtocolMessage
|
||
|
) => {
|
||
|
return {
|
||
|
userSeq: message.bodyList[0],
|
||
|
favorit: message.bodyList[1] === 'Y' ? true : false
|
||
|
} as BuddyUpdateResponse;
|
||
|
};
|