It lets you take an object or group of objects, put them on a disk or send them through a wire or wireless transport mechanism, then later, perhaps on another computer, reverse the process: resurrect the original object(s). The basic mechanisms are to flatten object(s) into a one-dimensional stream of bits, and to turn that stream of bits back into the original object(s).
자바 계열 RFC-2713에 따르면,
To "marshal" an object means to record its state and codebase(s) in such a way that when the marshalled object is "unmarshalled," a copy of the original object is obtained, possibly by automatically loading the class definitions of the object.
자바에서 마샬링은 객체의 상태를 포함해 원격 실행하고자 하는 오브젝트 코드의 URL까지 포함해 변환하는 것을 의미합니다.
이처럼 특정 로직을 수행하는 코드를 타 컴퓨터에서 원격으로 실행시키고자 할 때(이를 Remote Procedure Call이라고 함)에 마샬링을 사용할 수 있습니다.
마샬링은 주로 프로세스나 스레드 간 데이터 교환하거나 로직 수행을 요청해야할 때 사용합니다.
예제) 한 사람에 관한 정보를 갖는 객체
{
"이름": "홍길동",
"나이": 55,
"성별": "남",
"주소": "서울특별시 양천구 목동",
"특기": ["검술", "코딩"],
"가족관계": {"#": 2,"아버지": "홍판서","어머니": "춘섬"},
"회사": "경기 수원시 팔달구 우만동"
}
예제) 한 사람에 관한 정보를 갖는 객체
name: John Smith
age: 33
friends:
- Mary Smith
- Susan Williams
.proto
파일에 직렬화하고자 하는 데이터의 형식을 스키마 형태로 작성하면 소스 코드를 생성예제)
syntax = "proto2";
message messagePoint {
required int32 x = 1;
required int32 y = 2;
optional string label = 3;
}
message messageLine {
required Point start = 1;
required Point end = 2;
optional string label = 3;
}
message messagePolyline {
repeated Point point = 1;
optional string label = 2;
}
많은 도움이 되었습니다, 감사합니다.